<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>
<div  class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'商品管理',split:true" style="height:73px;background-color:#e6edfd;">
    	<form action="" id="promoSearchForm" name="promoSearchForm">
    	 <table class="screen">
			<tr>
				<td class="screen-n"><span>商品编码 </span></td>
				<td class="screen-n">
					<input type="text" id="search_productCode" class="screen-input"  style="width:200px"  onkeydown="pms.kd13('initpromoProductsTable')">
				</td>
				<td class="screen-n"><span>商品名称 </span></td>
				<td class="screen-n">
					<input type="text" id="search_chsName" class="screen-input"  style="width:200px"  onkeydown="pms.kd13('initpromoProductsTable')">
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initpromoProductsTable()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('promoSearchForm')" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		 </table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div> 
<script>

var promoProductsTable;
$(function(){
	initpromoProductsTable();
});
var toolbar = [
    {
	text:'新增促销商品',
    iconCls:'icon-add',
    handler:function(){
    	addPromoProductWin();
    }
} ];
function getParams(){
	var queryParamss = {
			"productCode":$('#search_productCode').val(),
			"chsName":$("#search_chsName").val()
	    };
	return queryParamss;
}
function initpromoProductsTable(){
	promoProductsTable = $('#tableGrid').pDataGrid({
		 toolbar:toolbar,
		 columns:[[
				  {field:'ck',checkbox:true},
	              {field:'productCode',title:'商品编号',align:'center'},
	              {field:'chsName',title:'商品显示名',width:180},
	              {field:'promoUrl',title:'专题链接',align:'center',width:200},
	              {field:'beginTime',title:'开始日期',align:'center',width:100},
	              {field:'endTime',title:'结束日期',align:'center',width:100},
	              {field:'sortOrder',title:'排序值',align:'center',width:40},
	              {field:'promoDesc',title:'促销简介',align:'center',width:300},
	              {field:'productSpec',title:'规格',align:'center',width:200},
	              {field:'packingUnit',title:'包装',align:'center'},
	              {field:'stockNum',title:'库存',align:'center',styler:function(){return 'background-color:#ffee00;color:red;';}},
	              {field:'producingName',title:'生产厂家',align:'center',width:200},
	              {field:'salePrice',title:'销售价',align:'center'},
	              {field:'retailPrice',title:'零售价',align:'center'},
	              {field:'brand',title:'品牌',align:'center'},
	              {field:'authorizeNumber',title:'批准文号',align:'center',width:150},
	              {field:'productTypeName',title:'分类',align:'center',width:100},

	              {field:'action',title:'操作',align:'center',formatter:function(value,row){
						return ' <a href="#" onclick="deletePromoP(\''+row.productCode+'\');">删除</a>';
		           }},
	          ]],
		    url:'<c:url value="/product/searchPageProductPromoList.do"/>',  
		    pagination:true,
		    pageSize:30,
		    fitColumns:false,
		    singleSelect:false,
		    queryParams:getParams(),
		    completeCallback:function(data){
				if(data.code == "100"){
					alertError(data.result);
				} 
			},
			onLoadSuccess : function(data) {
				var panel = $(this).datagrid('getPanel');
				var tr = panel.find('div.datagrid-body tr');
				tr.each(function() {
					var td = $(this).children('td[field="chsName"]');
					td.children("div").css({
						"text-align" : "left"
					});
				});
			}
	}); 
}

//新增促销展示商品信息
function addPromoProductWin(){
	$.pmsDialog({
		id:"w_product_promo",
		title:'新增促销展示商品',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_promo_detail.jsp"/>',
		width:900,
		height:400
	});
}
function deletePromoP(code){
	 
	var param = {"productCode":code};
	if(confirm("确定删除选择的商品?")){
		$.pmsAjax({
			url:'<c:url value="/product/deleteProductPromo.do"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("删除成功");
					promoProductsTable.refresh();
				}else{
					alertError(data.result);
				}
			}
		});
	}
}


function openProductAddOrSaveWindow(productCode){
	var params = {"productCode":productCode};
	$.pmsDialog({
		id:"w_product_save_add",
		title:'商品详情',
		method:'post',
		href:'<c:url value="/views/jsp/product/product_save_update_s.jsp"/>',
		width:1100,
		params:params,
		isIf:'true'
		
	});
}
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/product/searchPageProductPromoListExcel.do"/>',getParams());
} 

</script>
